package bz.ziro.kanbe.controller.mng.text;

import java.util.Date;
import java.util.logging.Logger;
import org.slim3.controller.Controller;
import org.slim3.controller.Navigation;
import org.slim3.datastore.Datastore;
import org.slim3.util.BeanUtil;

import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;

import bz.ziro.kanbe.bean.TextData;
import bz.ziro.kanbe.dao.SiteTextDao;
import bz.ziro.kanbe.model.SiteText;

/**
 * テキストの更新
 * @author Administrator
 */
public class UpdateController extends Controller {

    @SuppressWarnings("unused")
    private static final Logger logger = Logger.getLogger(UpdateController.class.getName());

    @Override
    public Navigation run() {
        //データを検索
        String keyBuf = param("textKey");
        SiteText text = SiteTextDao.find(Long.valueOf(keyBuf));

        //更新を行う
        BeanUtil.copy(request, text);

        UserService userService = UserServiceFactory.getUserService();
        User user = userService.getCurrentUser();

        //作成日を設定
        text.setEditDate(new Date());
        text.setEditor(user);

        Datastore.put(text);

        TextData.refreshTextMap();
        return null;
    }
}
